/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.pranavpandey.ohos.dynamic.toasts;

import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.agp.render.BlendMode;
import ohos.agp.utils.Color;

/**
 * 图片处理工具类
 *
 * @author ljh
 */
public class ImageTint {
    /**
     * 设置组件状态颜色值
     *
     * @param element 组件
     * @param colorStr 色值名称
     * @return 组件
     */
    public static Element getTintElement(Element element, String colorStr) {
        int intColor = Color.getIntColor(colorStr);
        return getTintElement(element, intColor);
    }

    /**
     * 设置组件状态颜色值
     *
     * @param element 组件
     * @param intColor 色值
     * @return 组件
     */
    public static Element getTintElement(Element element, int intColor) {
        return getTintElement(element, intColor, BlendMode.SRC_ATOP);
    }

    /**
     * 设置组件状态颜色值
     *
     * @param element 组件
     * @param intColor 色值
     * @param mode 模式
     * @return 组件
     */
    public static Element getTintElement(Element element, int intColor, BlendMode mode) {
        int[] colors = new int[]{intColor, intColor};
        int[][] states = new int[2][];
        states[0] = new int[]{0};
        states[1] = new int[]{0};
        element.setStateColorList(states, colors);
        element.setStateColorMode(mode);
        return element;
    }

    /**
     * 设置imageView 取值颜色背景
     *
     * @param view image
     * @param element 背景元素
     * @param colorStr 颜色
     */
    public static void setImageTint(Image view, Element element, String colorStr) {
        getTintElement(element, colorStr);
        setImageElement(view, element);
    }

    /**
     * 设置imageView 取值颜色背景
     *
     * @param view image
     * @param element 背景元素
     * @param intColor 颜色
     */
    public static void setImageTint(Image view, Element element, int intColor) {
        getTintElement(element, intColor);
        setImageElement(view, element);
    }

    /**
     * 设置imageView 取值颜色背景
     *
     * @param view image
     * @param element 背景元素
     * @param intColor 颜色
     * @param mode 模式
     */
    public static void setImageTint(Image view, Element element, int intColor, BlendMode mode) {
        getTintElement(element, intColor, mode);
        setImageElement(view, element);
    }

    /**
     * 设置imageView 背景
     *
     * @param view image
     * @param element 背景元素
     */
    public static void setImageElement(Image view, Element element) {
        view.setImageElement(element);
    }
}
